package cn.rokhdelar.ams.management.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.rokhdelar.ams.common.domain.vo.PageVO;
import cn.rokhdelar.ams.management.domain.po.SysDepartment;
import cn.rokhdelar.ams.management.domain.query.DepartmentQuery;
import cn.rokhdelar.ams.management.domain.vo.DepartmentVO;
import cn.rokhdelar.ams.management.mapper.SysDepartmentMapper;
import cn.rokhdelar.ams.management.service.SysDepartmentService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 针对表【sys_department(部门表)】的数据库操作Service实现
 * @author rokhdelar
 * @version 2024-10-02 13:08:48
*/
@Service
public class SysDepartmentServiceImpl extends ServiceImpl<SysDepartmentMapper, SysDepartment>
    implements SysDepartmentService{

    @Override
    @Transactional
    public PageVO<DepartmentVO> getDepartmentListByPage(DepartmentQuery query) {
        Page<SysDepartment> page = query.toPageDefaultSortByCreateTime();

        Page<SysDepartment> departmentPage = lambdaQuery()
                .like(query.getName() != null, SysDepartment::getName, query.getName())
                .eq(query.getStatus() != null, SysDepartment::getStatus, query.getStatus())
                .page(page);
        return PageVO.of(departmentPage, DepartmentVO.class);
    }

    @Override
    @Transactional
    public DepartmentVO getDepartmentById(String id) {
        SysDepartment sysDepartment = getById(id);
        return BeanUtil.copyProperties(sysDepartment, DepartmentVO.class);
    }
}




